﻿using System.Linq;
using Myotragus.Data.Registration;
using Myotragus.Data.RepositoryExtensions;
using Myotragus.Store.Model.Domain;
using Myotragus.Store.Model.DefaultRepositories;
using NUnit.Framework;

namespace Myotragus.Store.Model.Tests.StoreTests
{
  [TestFixture]
  public class DefaultsStoreModelFixture
  {
    [SetUp]
    public void SetUp()
    {
      FixtureHelper.InitializeServices(ServicesImplementation.FromAssemblyContaining<IProduct>());
      var entitites = new[] { typeof(ICategory), typeof(IProduct) };
      FixtureHelper.InitializeEntities(entitites);
      FixtureHelper.InitializeSession(entitites);
    }

    [Test]
    public void Read()
    {
      var repo = FixtureHelper.Container.Resolve<ICategoryRepository>();

      foreach (var list in FixtureHelper.LstCultureNames
        .Select(cul => repo.FindAll(FixtureHelper.GetLcId(cul))))
      {
        FixtureHelper.Print(list.First());
      }
    }

    [Test]
    public void DefaultsRead()
    {
      var repo = FixtureHelper.Container.Resolve<ICategoryRepository>();

      var item10 = repo.FindAll(10).First();

      repo.SetDefaultLcId(item10.Id, 10);
      var item999 = repo.FindAll(999).First();
      Assert.IsNotNull(item999.Name);
      Assert.AreEqual(item10.Name, item999.Name);
    }
  }
}